/**
 * @author: yuCloud
 * @desc: 封装localStorage
 * @params:
 * @type:
 * @time: 2023-03-27 19:07:55
 **/
import config from "@/config/index.js";

const setStorageItem = (key, value) => {
    let storage = getStorage()
    storage[key] = value
    window.localStorage.setItem(config.namespace, JSON.stringify(storage))
}
// 获取某个模块下面的属性
const getStorageItem = (key) => {
    return getStorage()[key]
}

// 获取整个localStorage
const getStorage = () => {
    return JSON.parse(window.localStorage.getItem(config.namespace) || '{}')
}
// 清除存储某个模块下面的属性
const clearStorageItem = (key) => {
    let storage = getStorage()
    delete storage[key]
    window.localStorage.setItem(config.namespace, JSON.stringify(storage))
}

// 清除整个localStorage
const clearStorage = () => {
    window.localStorage.removeItem(config.namespace)
}

export {
    setStorageItem,
    getStorageItem,
    getStorage,
    clearStorageItem,
    clearStorage
}
